package net.csdn.business.auth.listener.handler;


import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Desc: 
 * @ClassName: CustomAuthenticationFailureEventHandler
 * @Author: yourleige@163.com
 * @Date: 2022/9/27 13:54
 */
@Slf4j
@Component
@AllArgsConstructor
public class CustomAuthenticationFailureEventHandler implements AuthenticationFailureHandler {


	/**
	 * 异步处理，登录失败方法
	 * @param exception 登录的authenticationException 对象
	 * @param request 请求
	 * @param response 响应
	 */
	@Override
	public void handle(AuthenticationException exception, Authentication authentication,
			HttpServletRequest request, HttpServletResponse response) {
		String username = authentication.getName();
        String message=exception.getLocalizedMessage();
		log.info("用户：{} 登录失败，异常：{}", username, message);

	}
}
